package com.explorati.LeetCode404.isLeftNode;

import com.explorati.LeetCode404.isLeftNode.Solution.TreeNode;

/**
 * 404. Sum of Left Leaves
 * 
 * @author explorati
 *
 */
public class Solution1 {
	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

	int sum = 0;

	public int sumOfLeftLeaves(TreeNode root) {
		if (root == null) {
			return sum;
		}
		if (root.left != null && root.left.left == null && root.left.right == null) {
			sum += root.left.val;
		}

		if (root.left != null) {
			sumOfLeftLeaves(root.left);
		}
		if (root.right != null) {
			sumOfLeftLeaves(root.right);
		}

		return sum;
	}

}
